var LoadingScene = (function(){

    function LoadingScene(){
        Scene2D.call(LoadingScene,true);
        this.timeFlag = 0;
        this.lodingValue = 0;
        this.loadedValue = 0;
        this.oneFrameLoadingValue = 2;
        //加载完成后的回调函数
        this.callbackFunc = null;
    }

    LoadingScene.prototype = new Scene2D();

    var __proto = LoadingScene.prototype;
    __proto.initScene = function(node){
        this.bg.height += offH;
        this.bg.y -= offH/2;

        // 游戏忠告提
        this.loading_bg.height += offH ;
        this.loading_bg.y -= offH/2;
        this.loading_bg_1.y = this.loading_bg.height - 420;
        this.loading_bg_2.y = this.loading_bg.height - 130;
    //   this.PrivacypolicyPanel.height += offH;
    //     this.PrivacypolicyPanel.y -= offH/2;


        
        this.progress_bar.width = 0;
        this.progress_text.text = "0%"
        if(Config.channelID == 102){
            this.progress_text.fontSize -= 50
        }
        Laya.LocalStorage.setItem("isConsetGame", "0");
         if (!Laya.LocalStorage.getItem("isConsetGame")) {
            Laya.LocalStorage.setItem("isConsetGame", "0");
                console.log("第一次");
        }

        if(Config.channelID == 101&&Laya.LocalStorage.getItem("isConsetGame")==0){

                  this.PrivacypolicyPanel.visible = true;
               
        }else
        {
            this.PrivacypolicyPanel.visible = false;
        }
    };
    __proto.onActive = function(from){
        // if(Config.channelID == 101 || Config.channelID == 2 || Config.channelID == 102){
        //     this.oneFrameLoadingValue = 10;
        // }else{
        // }
        // Laya.timer.frameLoop(1, this, this.onloop);
        
        // // 游戏忠告提示开启
        // this.loading_bg.visible = true;
        // // 游戏忠告提示关闭
        // Laya.timer.once(2000, this, function() {
        //     this.loading_bg.visible = false;
        // })
        
        if (Config.channelID == 101) {
                console.log("写入前"+Laya.LocalStorage.getItem("isConsetGame"));
                    if (Laya.LocalStorage.getItem("isConsetGame") == "0") {
                        this.PrivacypolicyPanel.visible = true;
                    this.consentBtn.on(Laya.Event.MOUSE_DOWN, this, () => {
 
                     Laya.LocalStorage.setItem("isConsetGame", "1");
                    console.log("写入后"+Laya.LocalStorage.getItem("isConsetGame"));
                 
                    Laya.timer.frameLoop(1, this, this.onloop);

                    // 游戏忠告提示开启
                 this.loading_bg.visible = true;
                     // 游戏忠告提示关闭
                     Laya.timer.once(2000, this, function() {
                            this.loading_bg.visible = false;
                     })
                });
                        
                        this.cancelBtn.on(Laya.Event.MOUSE_DOWN, this, () => {
                                 qg&&qg.exitApplication({});

                        });

                    }else{
                         Laya.timer.frameLoop(1, this, this.onloop);

                    // 游戏忠告提示开启
                 this.loading_bg.visible = true;
                     // 游戏忠告提示关闭
                     Laya.timer.once(2000, this, function() {
                            this.loading_bg.visible = false;
                     })
                    }
       
    };
      Laya.timer.frameLoop(1, this, this.onloop);
    };
 
    __proto.onInActive = function(){
        Laya.timer.clearAll(this);
        this._node.visible = false;
    };

    __proto.onloop = function(){
        if(this.loadedValue < this.lodingValue){
            this.loadedValue += this.oneFrameLoadingValue;
            if(this.loadedValue > this.lodingValue){
                this.loadedValue = this.lodingValue
            }
            var positionX = 833/100 * this.loadedValue;
            this.progress_duck.x = positionX;
            if(Config.channelID == 102){
                var str = this.loadedValue+"%"
                this.progress_text.text = Tool.insertSpace(str);
                // this.progress_text.text = this.loadedValue+"%";
            }else{
                this.progress_text.text = this.loadedValue+"%";
            }
            this.progress_bar.width = positionX;
        }
        if(this.loadedValue == 100){
            if(this.callbackFunc){
                this.callbackFunc();
                this.onInActive();
            }
        }
    };
    __proto.increaseLodingValue = function(increaseValue){
        this.lodingValue += increaseValue;
        if(this.lodingValue > 100){
            this.lodingValue = 100;
        }
    }
    __proto.setLoadedCB = function(cbFunc){
        this.callbackFunc = cbFunc;
    }
    
    return LoadingScene;
})();